package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Override
    public PageResponse<NursingLevelVo> selectByPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page page = (Page) nursingLevelMapper.selectByPage(name,status);
        PageResponse<NursingLevelVo> of = PageResponse.of(page, NursingLevelVo.class);
        return of;
    }

    @Override
    public List<NursingLevelVo> selectAll() {
        List<NursingLevelVo> list = nursingLevelMapper.selectByPage("",null);
        return list;
    }

    @Override
    public void addNursingLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevel.setIsDelete(0);
        nursingLevelMapper.addNursingLevel(nursingLevel);
    }

    @Override
    public NursingLevelVo selectById(Integer id) {
        NursingLevelVo nursingLevelVo = nursingLevelMapper.selectById(id);
        return nursingLevelVo;
    }

    @Override
    public void updateNursingLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.updateNursingLevel(nursingLevel);
    }

    @Override
    public void deleteNursingLevel(Integer id) {
        nursingLevelMapper.deleteNursingLevel(id);
    }

    @Override
    public void isForbidden(Integer id, Integer status) {
        nursingLevelMapper.updateStatus(id,status);
    }

}
